﻿$(document).ready(function () {
    $('#side_menu_btn').click(function (e) {
        if (!checkActiveLeft()) {
            $('#bodyLeft').animate({ left: 0 }, 500);
            $('#bodyRight').animate({ left: 260 }, 500, function () {
                $(this).attr("control", "active-left");
            });
        } else {
            $('#bodyLeft').animate({ left: -260 }, 500);
            $('#bodyRight').animate({ left: 0 }, 500, function () {
                $(this).removeAttr("control", "active-left");
            });
        }
    });


    $('.manufacture select').change(function () {
        location.href = "/Danh-Muc/" + $(this).val() + "/" + locdau($(this).find('option:selected').text());
    });

    $('.divDetail p').first().remove();

    $('#side_search_box_input').focus(function () {
        $('.search_bottom').css('display', 'block');
    });

    $('.search_bottom input[type=button]').click(function () {
        var textSearch = $.trim($('#side_search_box_input').val());
        if (textSearch != '') {
            location.href = '/Tim-Kiem?key=' + textSearch
        }
    });
});

function checkActiveLeft() {
    if ($('#bodyRight').attr("control") == "active-left") {
        return true;
    }
    return false;
}

function locdau(str) {
    str = str.toLowerCase();
    str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a");
    str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
    str = str.replace(/ì|í|ị|ỉ|ĩ/g, "i");
    str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o");
    str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
    str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
    str = str.replace(/đ/g, "d");
    str = str.replace(/!|@|\$|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\'| |\"|\&|\#|\[|\]|~/g, "-");
    str = str.replace(/-+-/g, "-");
    str = str.replace(/^\-+|\-+$/g, "");
    str = str.replace(/\-\-/g, "-");
    return str;
}